home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / basic / qbnws201.zip / ELEAVE.ZIP / ELEAVE.ASM next >
Assembly Source File  |  1991-02-28  |  2KB  |  60 lines

  1. ;ELEAVE.ASM - Routine to return an error level from a QuickBASIC
  2. ;program
  3. ;
  4. ;********** WARNING **********
  5. ;Do not run in the QB environment
  6. ;
  7. ;By David Cleary
  8.  
  9. .Model Medium, Basic
  10.  
  11. .Code
  12.  
  13.    Extrn       B$CEND:Proc             ;QB termination proceedure
  14.  
  15.    Level       DW 0
  16.    OldIntOfs   DW 0
  17.    OldIntSeg   DW 0
  18.  
  19. ELeave Proc , ELevel:Ptr Word
  20.  
  21.    Mov   BX, ELevel                    ;Get the level passed in
  22.    Mov   AX, [BX]
  23.    Mov   CS:Level, AX                  ;Save it in Level
  24.  
  25.    Mov   AX, 3521h                     ;Call DOS to get its int vector
  26.    Int   21h
  27.    Mov   CS:OldIntOfs, BX              ;ES:BX points to old vector
  28.    Mov   CS:OldIntSeg, ES
  29.  
  30.    Mov   AX, 2521h                     ;Now set our new int vector
  31.    Mov   DX, Offset IntTrap
  32.    Push  DS
  33.    Push  CS
  34.    Pop   DS                            ;Save DS and move CS into it
  35.    Int   21h
  36.    Pop   DS                            ;Restore DS
  37.    Call  B$CEND                        ;Call BASIC to end
  38.  
  39. IntTrap:
  40.    Cmp   AH, 4Ch                       ;Wait for function 4C
  41.    Jne   ChainOld                    ;If not, chain to original vector
  42.  
  43.    Sti                               ;It is 4C, so turn interrupts on
  44.    Mov   AX, 2521h                     ;Restore original vector
  45.    Mov   DX, CS:OldIntOfs
  46.    Mov   DS, CS:OldIntSeg
  47.    Call  CS:DWord Ptr OldIntOfs   ;We need to call it instead of chain
  48.  
  49.    Mov   AX, CS:Level
  50.    Mov   AH, 4Ch                       ;Call INT 21h function 4Ch with
  51.                                        ;our level
  52.    Int   21h
  53.  
  54. ChainOld:
  55.    Jmp   CS:DWord Ptr OldIntOfs     ;This is our chain to the original
  56.  
  57. ELeave Endp
  58.  
  59. End
  60.